<?php
namespace Admin\Controller;

class RegbusiController extends AdminBaseController
{
   public function index()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $this->display('regbusi/index');
    }
    
    public function rlist(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $page=I('page',1);
        $rows=I('rows',50);
        $start=($page-1)*$rows;
       
        $RegisterBusiness = M('RegisterBusiness');
        $list = $RegisterBusiness->limit($start,$rows)->select();
        $count = $RegisterBusiness->count();
        $map=array(
            'rows'=>$list,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    public function tosave(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
      $this->display("regbusi/save");
    }
    
    public function save(){
        $RegisterBusiness=M('RegisterBusiness');
        $data['name']=I('name','');
        $old = $RegisterBusiness->where($data)->select();
        if(!empty($old)){
            $map=array(
                'status'=>2
            );
            $this->ajaxReturn($map,'JSON');
            exit();
        }
        $data['platformcode']=I('platformcode','');
        $data['check']=I('check','');
        $RegisterBusiness->add($data);
        $map=array(
            'status'=>1
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    
    public function update(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $id=I('id','');
        $RegisterBusiness=M('RegisterBusiness')->find($id);
        $this->ajaxReturn($RegisterBusiness,'JSON');
    }
    
    public function toupdate(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $data['name']=I('name','');
        $data['platformcode']=I('platformcode','');
        $data['check']=I('check','');
        M('RegisterBusiness')->where('id='.I('id',''))->save($data);
        $map=array(
            'status'=>1
        );
        $this->ajaxReturn($map,'JSON');
    }
    
}